<?php
$title="会员管理";
$css="userList.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$users=$db->load_users();
$totalUser=count($users)-1;
$numPerPage=4;
$totalPage=ceil($totalUser/$numPerPage);
$page=$_GET['page']; //获得当前的页面值
if (!isset($page)) {
 $page=1;
} //如果没有值,则赋值1
if($page>$totalPage)
{
	$page--;
}
$startCount=($page-1)*$numPerPage; //分页开始,根据此方法计算出开始的记录
$users=$db->get_user_limit($startCount+1,$numPerPage);
?>
<div id="userlist" align="center">
<table id="userlistTable" border="1" style="margin-top:20px;font-size: 12pt;">
	<tbody>
		<tr style="color:white;">
			<th width="90px"><p>用户名</p></th>
			<th><p>性别</p></th>
			<th><p>等级</p></th>
			<th width="88px"><p>手机</p></th>
			<th width="150px"><p>E-Mail</p></th>
			<th width="170px"><p>常用收货地址</p></th>
			<th width="20px"></th>
		</tr>
		<?php 
		$i=0;
		while(isset($users[$i]))
		{
		?>
		<tr style="color:white;">
			<td width="90px" align="center"><p><a href="modifyuser.php?page=<?php echo $page;?>&id=<?php echo $users[$i]["uid"];?>"><?php echo $users[$i]["userName"];?></a></p></td>
			<td align="center"><p><?php echo $users[$i]["sex"]=="0"?"男":"女";?></p></td>
			<td align="center"><p><?php echo $users[$i]["level"];?></p></td>
			<td><p><?php echo $users[$i]["phone"];?></p></td>
			<td align="center" width="150px" style="word-break:break-all;"><p><?php echo $users[$i]["email"];?></p></td>
			<td width="170px" style="word-break:break-all;"><p><?php echo $users[$i]["deliver_addr"];?></p></td>
		    <td width="30px" align="center"><a href="userDelete.php?id=<?php echo $users[$i]["uid"];?>&page=<?php echo $page;?>">
				<img alt="x" src="../image/delete.png" width="14">
			</a></td>
		</tr>
		<?php 
		$i++;
		}
		?>
	</tbody>
</table>
        	<div id="page">
			<?php if ($page != 1) { //页数不等于1?>
			<a href="userList.php?page=<?php echo $page - 1;?>">上一页</a> <!--显示上一页-->
			<?php }
			for ($i=1;$i<=$totalPage;$i++) {  //循环显示出页面
				if($i==$page){
					?>
					<p><?php echo $i;?></p>
			<?php continue;}
			?>
			<a href="userList.php?page=<?php echo $i;?>"><?php echo $i ;?></a>
			<?php
			}
			if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
			?>
				<a href="userList.php?page=<?php echo $page + 1;?>">下一页</a>
			<?php
					} 
			?>
			
			</div>
</div>
<?php 
include_once 'common/AdminTail.php';
?>